package com.glodon.paas.activity.util;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import com.glodon.paas.activity.dao.domain.ActivityEntity;
import com.glodon.paas.util.ObjectUtil;

public class BatchDownLoadFileTemplateTest_ext1 {

    public static void main(String[] args) throws FileNotFoundException {
        StringWriter writer = new StringWriter();

        // context
        ActivityEntity contextObject = new ActivityEntity();
        contextObject.setActorId("hc");
        contextObject.setActorName("黄诚");
        
        Map<String,Object> ext = new HashMap<String,Object>();
        ext.put("itemIds", new String[]{"nsrjsyt","sangyyi","xyouj"});
        ext.put("itemNames", new String[]{"你是人间四月天.doc","三国演绎.pdf","西游记"});
        ext.put("size", 3);
         
        contextObject.setExt1(ObjectUtil.toJson(ext));

        VelocityContext context = VelocityContextWrapActivity.wrap(contextObject);

        InputStream vm = Thread.currentThread().getContextClassLoader().getResourceAsStream("BatchDownLoadFileTemplate_ext1.vm");
        Reader reader = new InputStreamReader(vm);
        Velocity.evaluate(context, writer, "mystring", reader);
        System.out.println(writer.toString());
    }

}
